package chamans.webphp
{
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.text.*;
	import flash.xml.*;
	
public class Liste extends MovieClip
		{
		
//var Base:Object
private var style:StyleSheet// = new StyleSheet()
//private var police:String="Trebuchet MS"
//private var police:String="Times";

private var col:Number
public var XMLO:String
public var xml:XML

public var TYPES:Array;
private var LISTE:Boolean=true;
private var SCROLL:MovieClip;
//private var objID : Array=new Array();
private var objID:Vector.<MovieClip>;
private var externalXML:XMLDocument=new XMLDocument();
private var Max:Number=0;
private var H:Number=0;
private var titreImg:Bitmap
private var loader:URLLoader 
private var cc:Object
private var NewListe:MovieClip
private var masking:Sprite;
private var BitTitre:Bitmap;
public var action:Function;
private var Contour:Sprite;

private var config:Object={
	sizeX:260,
	sizeY:175,
	buttonY:24,
	buttonPosY:25,
	DecaleTitre:25,
	scrollSize:20,
	scrollon:false
	}
	public function Liste(S:StyleSheet):void {
		style=S;
		objID = new Vector.<MovieClip>();
				}
public function LOAD( link:String="" ):void{
	
    if (link) XMLO=link
	loader  = new URLLoader ()
	loader.load(new URLRequest(XMLO))
	loader.addEventListener(Event.COMPLETE, DIRECT)	
}

public function DIRECT(event:Event=null):void {
	//style.setStyle("button", {fontSize:'14px', fontFamily:police, color:'#DDDDDD', fontWeight : "bold", textAlign :"center"})
   // style.setStyle("titre", {fontSize:'14px', fontFamily:police, color:'#DDDDDD', fontWeight : "bold", textAlign :"center"})

	if(NewListe!=null){Clear(NewListe); removeChild(NewListe); NewListe=null}
	if(BitTitre!=null){  removeChild(BitTitre); BitTitre=null}
	if(Contour!=null){  removeChild(Contour); Contour=null}
	var xmlpp:XML
	var TOP:txt
	var loader:URLLoader;
	var BG:Sprite;
	var xml8:XML;
	var Ctexte:String
	var i:int;
	var j:int;
	var Bit:Bitmap
	var Te:txt
	
	with(config){
	NewListe=new MovieClip();
	
	Contour=carre( 0xFF0000, 0, sizeX-1, sizeY-DecaleTitre-1, 0, DecaleTitre, true)
	addChild(Contour)
	Contour.mouseEnabled=false;
	Contour.mouseChildren=false;
	//TITRE
	xmlpp=<xml></xml>;xmlpp.titrelist="DATA"
	TOP=new txt({ text:xmlpp, target:this, style:style, width:250,height:buttonY,  x:0, y:5}) 
	Effect( TOP.TX ) // ombre
	BitTitre=bitmap( TOP.TX )
	this.addChild(BitTitre);TOP.clear()
	
     //MASK
	masking=carre( 0xFF0000, .3, sizeX, sizeY-DecaleTitre )
	//masking=new face(  sizeX, sizeY-DecaleTitre, 0, 0xFF0000, .3 )
	masking.y=DecaleTitre
	masking.visible=false
	this.addChild(masking)
    this.addChild(NewListe)
	
	NewListe.mouseEnabled=false;
    NewListe.mouseChildren=true;
	
	if(event){loader=URLLoader(event.target);  xml=new XML(loader.data); }
	externalXML.ignoreWhite = true;
    externalXML.parseXML(xml.toXMLString());
	
	rootNode = externalXML.firstChild.childNodes;
	Max = rootNode.length
    CheckScroll( (Max)*buttonPosY )
	
	
	for( i = 0; i < Max; i++) {
		//creation des Boutons
		Mo=new MovieClip()
		
		if(scrollon) BG=carre( 0x333333, 1, sizeX-scrollSize, buttonY )
		else BG=carre( 0x333333, 1, sizeX, buttonY )
		Mo.addChild(BG)
		Mo.BG=BG
		
		for(  j = 0; j < TYPES.length; j++ ){
			xml8=<xml></xml>;
			//recuperation de Donnée
			 Ctexte = externalXML.childNodes[0].childNodes[i].attributes[TYPES[j]]
		 if(j< TYPES.length-1){
		     if(j==0) { xml8.liste1=Ctexte;
			 Te=new txt({ text:xml8, target:this, style:style, width:20,height:20,  x:10, y:2 }) 
			 } else if (j==1){ xml8.liste2=Ctexte;
			 Te=new txt({ text:xml8, target:this, style:style, width:70,height:20,  x:35, y:2 }) 
			 }  else {xml8.liste3=Ctexte;
			 Te=new txt({ text:xml8, target:this, style:style, width:120,height:20,  x:110, y:2 }) 
			 }
			
			// Effect( Te.TX ) // ombre
			 Bit=bitmap( Te.TX )
			 Mo.addChild( Bit ) 
			// Te.TX.filters = null
			 Te.clear()
		  } else{       
		//  this["btn"+i].Message=Ctexte
		}}
		
		
		Mo.id=i
		Mo.y=(i * (buttonPosY))+DecaleTitre;
		Mo.BG.alpha=.1
		Mo.mouseChildren=false;
		Mo.buttonMode=true;
		
		Mo.addEventListener ('mouseOver',MOver);
	    Mo.addEventListener ('mouseOut',MOut);
		Mo.addEventListener ('click',MPress);
		
		
		
		objID.push(Mo)
		NewListe.addChild(objID[i]);
}}}
private function Clear(target:MovieClip):void {
	while(target.numChildren) target.removeChildAt(0);
}

private function MOver(e:MouseEvent):void {
	var id:int = e.target.id;
	//this["btn"+id]
	objID[id].BG.alpha=1
}
private function MOut(e:MouseEvent):void {
	var id:int =e.target.id;
	objID[id].BG.alpha=.1
}
private function MPress(e:MouseEvent):void {
	var id:int =e.target.id;
	action(id)
}

private function CheckScroll( T:Number ):void {	with(config){
	if (T >masking.height){ 
 if(SCROLL==null ){
	SCROLL=new Scroll(); 
	this.addChild(SCROLL);
	scrollon=true
	}
	NewListe.mask = masking;
     SCROLL.init(scrollSize, sizeX-scrollSize, DecaleTitre, sizeY-DecaleTitre, NewListe, T);
	 SCROLL.ActiveScroll();
	}
	
    else{//pas de Scroll 
	scrollon=false
	if(SCROLL!=null){SCROLL.inActiveScroll();removeChild(SCROLL); SCROLL=null}
	}}}
	
	
public function GOTO(Target:String, Id:Number=0, S:Boolean=true):void{
	if(S)LISTE=false;
	XMLO = Target; 
	this["btn"+Id].removeEventListener ('mouseOut',MOut);
	loader.load(new URLRequest(XMLO));
    loader.addEventListener(Event.COMPLETE, DIRECT);
	}
public function CLEAR():void{
	for each (var item:* in objID){	var id:int= objID.indexOf(item);
	if(this["btn"+id]){
	this["btn"+id].removeEventListener ('mouseOver',MOver);
	this["btn"+id].removeEventListener ('mouseOut',MOut);
    NewListe.removeChild(this["btn"+id]);
	}}
	this.removeChild(BitTitre);
	}
private function Effect(OBJ:*,V:Boolean=true):void{
	OBJ.filters = [ new DropShadowFilter(2, 45, 0x000000, .6,2,2, 1, 3) ]
	}
//______________graph
private function bitmap( cible:* ):Bitmap{ 
        var B:Bitmap
        var Bitm:BitmapData= new BitmapData( cible.width, cible.height,true,0x00);
	    Bitm.draw(cible);
		B=new Bitmap(Bitm)
		B.x=cible.x;B.y=cible.y;
	return B 
	}
private function carre( c:int, a:Number, w:int, h:int, x:int=0, y:int=0, l:Boolean=false ):Sprite{ 
	var G:Sprite=new Sprite;
	if(l)G.graphics.lineStyle(0,0x999999)
	G.graphics.beginFill(c,a); G.graphics.drawRect(x,y,w,h); G.graphics.endFill()
	return G  }


	}}